﻿@using ST = EmoneyWeiXinCommon.StringTools;
@{
    ViewBag.Title = "单一素材管理";
    Layout = "~/Views/Shared/_Layout.cshtml";
}
<script type="text/javascript" src="@ST.GetStaticFile("My97DatePicker/WdatePicker.js")"></script>
<div class="right">
    <h3>单一素材管理</h3>
    <!--manage-->
    <div class="manage">
        <!--manage_top-->
        <div class="manage_top">
            <ul class="manage_top_ul">
            </ul>
            <div class="manage_register">

                <p><span>名称：</span><input type="text" id="txtTitle"></p>
                <p>
                    <span>添加时间：</span>
                    <input type="text" class="manage_register_text" onfocus="WdatePicker()" id="txt_startTime"><span class="manage_register_font">至</span><input type="text" class="manage_register_text" onfocus="WdatePicker()" id="txt_endTime">
                </p>
            </div>
            <p class="manage_add">
                <a href="javascript:void(0)" id="btnSearch">查询</a>
            </p>
        </div>
        <!--manage_top end-->
        <p class="manage_line"></p>
        <!--manage_bottom-->
        <div class="manage_bottom">
            <!--manage_bottom_title-->
            <!--manage_bottom_title--end-->
            <table border="0" cellpadding="0" cellspacing="0" width="100%" id="dataTable">
                <tr>
                    <th><span>名称</span></th>
                    <th><span>素材类型</span></th>
                    <th><span>mediaId</span></th>
                    <th><span>ImgUrl</span></th>
                    <th><span>发布时间</span></th>
                </tr>
            </table>
            <div class="manage_page" id="manage_page">
                <ul>
                </ul>
            </div>
        </div>
        <!--manage_bottom end-->
    </div>
    <!--manage end-->
</div>

<script type="text/javascript">
    var weixinid = "";
    var pageIndex = 1;
    var pageSize = 10;
    var pageCount = 1;
    var totalCount = 0;
    var viewBagWeixinId = "@ViewBag.weixinid";
    var orderBy = " UpdateTime desc";
    var getUserMenuUrl = "@ST.GetTrendsFile("BaseConfiguration/WeixinUserMemu")" + "?random=" + Math.random();
    var getTJBusinessDataUrl = "@Url.Action("GetListByPage", "MaterialManage")";
    $(document).ready(function () {
        createMemu();
        initEvents();
        getListData();

    });


    //翻页
    function PageCountHtml() {
        pageCount = Math.ceil(totalCount / pageSize);
        if (pageCount == 0) {
            pageCount = 1;
        }
        $("#manage_page").html(PageHtml(pageIndex, pageCount));
        $("#manage_page .manage_page_right").on("click", function () {
            pageIndex = pageIndex + parseInt($(this).attr("tname"));
            getListData();

        });

        $("#manage_page .tiaozhuan").click(function () {
            var pageNum = $("#txtPageNum").val();
            var tempIndex;
            try {
                tempIndex = parseInt(pageNum);
            } catch (e) {
                alert("请输入数字");
                return false;
            }

            if (pageNum > 0 && pageNum <= pageCount) {
                pageIndex = tempIndex;
                $("#manage_page").html(PageHtml(pageIndex, pageCount));
                getListData();

            }
            else {
                alert("当前数字超出范围");
                return false;
            }

        });

    }

    function getContentMemu() {
        $(".manage_top_ul .manage_top_A").each(function () {
            weixinid = $(this).attr("typeid");
        })
        if (weixinid > 0) {
            bindMemuType("pType", "@ST.GetTrendsFile("Report/GetMemuTypeList")", function (result) {
        }, weixinid);
    }
}
//创建labs
function createMemu() {
    $.ajax({
        type: "get",
        url: getUserMenuUrl,
        async: false,
        data: { weixinid: viewBagWeixinId },
        dataType: "html",
        success: function (result) {
            $(".manage_top_ul").html(result);
            $(".manage_top_ul li").click(function () {
                $(".manage_top_ul li").removeClass("manage_top_A");
                $(this).addClass("manage_top_A");
                getContentMemu();
                getListData();

            })
            getContentMemu();
        }
    });
}


function initEvents() {
    $("#btnSearch").click(function () {
        pageIndex = 1;
        getListData();
    });

}

//重画
function render(data) {
    totalCount = data.totalCount;
    PageCountHtml();
    var dataList = data.dataList;
    var $dataTable = $("#dataTable");
    $dataTable.find("tr:gt(0)").remove();
    for (var i = 0; i < dataList.length; i++) {
        var newTr = creatNewRow(dataList[i]);
        $dataTable.append(newTr);
    }

}

function creatNewRow(rowData) {
    var $newRow = $("<tr><td>" + rowData.Ma_Name + "</td><td>" + rowData.Ma_Type + "</td><td>" + rowData.Media_id + "</td><td>" + rowData.ImgUrl + "</td><td>" + rowData.UpdateTime.replace(/T/g, " ").substring(0, 10) + "</td></tr>");
    return $newRow;
}

function getListData() {

    var paraData =
        {
            size: pageSize,
            index: pageIndex,
            weixinId: weixinid,
            orderBy: orderBy
        };

    $.ajax({
        url: getTJBusinessDataUrl,
        type: 'post',
        data: paraData,
        dataType: 'json',
        success: function (data) {
            render(data);
        }
    });

}

function initData() {

}
</script>
